import Vue from 'vue'
import Vuex from 'vuex'

// 插件化的方式 注册vuex
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    cart:uni.getStorageSync('cart') || []
  },
  getters:{
    getCartCuont(state){
      return  state.cart.filter(item=>item.goods_checked === true)
    },
    getCountZong(_,getters){
      
     return getters.getCartCuont.reduce((prev,item)=>{
      return prev + item.goods_number
     },0)
    }
  },
  mutations:{
    yjkaddGoodsList(state,payload){
      state.cart = payload
      uni.setStorage({
        key:'cart',
        data:payload
      })
    }
  }
})

// commonjs ---  module.exports + require
// es6 module --- export + import
export default store